import React from 'react';

import ActionManger from '../ActionManager';

export default class BaseAction {
  constructor() {
    this.data = null;
    this.moduleType = "";
  }

  _getActionName() {
    return this.name;
  }

  //为了兼容以前，这这么写吧
  call(caller, data) {
    // console.log("caller action" + this._getActionName());
    this._dealCall(caller, data);
    this._baseCall(caller, data);
  }

  _dealCall(caller, data) {

  }

  _baseCall(caller, data) {
    this.caller = caller;
    this.data = data === undefined ? null : data;
    ActionManger.call(this);
  }

  finish(responseJson, isSucceed) {

  }

  _dealUnauthorized(errorDetail) {
    if(this.caller){
       this.caller.setState({
          authorization: -1,
          authorizationErrorDetail: errorDetail ? errorDetail : null,
        })
    }
  }

  _dealFinishFailed(data, response) {
    let detail = "服务器错误";
    if(data && data.detail != undefined) {
      detail = data.detail;
    }
    this.caller.setState({
      viewStatus:response.status,
      statusText:detail + " " + response.status,
    })
  }

  _dealFinishSucess(data, response) {

  }
}
